package com.yequan.designpattern.proxy.dynamic_proxy.jdk.first_generation;

import com.yequan.designpattern.proxy.dynamic_proxy.GamePlayer;
import com.yequan.designpattern.proxy.dynamic_proxy.IGamePlayer;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class FirstGenerationJdkTest {

    public static void main(String[] args) {
        IGamePlayer gamePlayer = new GamePlayer("叶权");
        InvocationHandler handler = new GamePlayInvocationHandler(gamePlayer);

        ClassLoader classLoader = gamePlayer.getClass().getClassLoader();
        IGamePlayer proxyInstance = (IGamePlayer) Proxy.newProxyInstance(classLoader, new Class[]{IGamePlayer.class}, handler);

        proxyInstance.login("yequan", "1");
        System.out.println("\n");
        proxyInstance.killBoss();
        System.out.println("\n");
        proxyInstance.upgrade();
    }

}
